package reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.doSome();

        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();

        Method method = cls.getMethod("doSome");
        method.invoke(obj);

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入类名:");
        Class cls2 = Class.forName(scan.nextLine());
        Object obj2 = cls2.newInstance();
        System.out.println("请输入方法名:");
        String methodName = scan.nextLine();
        Method method2 = cls2.getMethod(methodName);
        method2.invoke(obj2);


    }
}
